package com.gdkm.database.service;

import com.gdkm.database.annotation.DataSourceSwitcher;
import com.gdkm.database.domain.User;
import com.gdkm.database.enums.DataSourceEnum;
import com.gdkm.database.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author HD-0078 杨炜耀
 * @date 2021-5-7 09:25
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 添加新用户
     */
    @Transactional
    public void insertUser(User user){
        if(this.userMapper.insertUser(user) == 0){
            throw new IllegalArgumentException("user argument exception.");
        }

    }


//    @DataSourceSwitcher(DataSourceEnum.SLAVE)
    public List<User> listUser(){
        return this.userMapper.getUser();
    }

}
